import { Validator } from "../lib/validator.js";
import * as Common from '../common.js'
var url = Common.UrlBase + Common.ApiEnums.UserMgr;

export class NetApi
{
    static NetHttpAddUserGoods(gid, counts, cb)
    {
        var user_id = $.cookie('user_id');
        if (Validator.isEmpty(user_id))
        {
            console.error("NetHttpAddUserGoods user_id为空");
            return;
        }
        console.log("发送请求" + url);
        $.post(
            url,
            {
                "action": "addUserGoods",
                "user_id": user_id,
                "goods_id": gid,
                "counts": counts
            }, (res) =>
        {
            cb(res);
        });
    }

    static NetHttpUpdateUserKvByid(gidi, newcounts, cb)
    {
        var user_id = $.cookie('user_id');
        if (Validator.isEmpty(user_id))
        {
            console.error("NetHttpAddUserGoods user_id为空");
            return;
        }
        console.log("发送请求NetHttpUpdateUserKvByid" + url);
        $.post(
            url,
            {
                "action": "updateUserKvByid",
                "user_id": user_id,
                "key": gidi == 16 ? "tael" : "coin",
                "val": newcounts,
                "val_type": 0
            }, (res) =>
        {
            cb(res);
        });
    }
}